﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prob_Distributions_ClassLibrary
{
    class DistribucionNormal : IDistribucion
    {
        private RandomNumber rnd;
        private double promedio;
        private double desviacion;
        private double mayor;
        private double menor;
        public DistribucionNormal(RandomNumber rnd, double promedio, double desviacion)
        {            
            this.rnd = rnd;
            this.promedio= promedio;
            this.desviacion = desviacion;
        }

        public List<double> getNRandoms(int cant)
        {
            List<double> lstRandoms = new List<double>();
            List<double> r = rnd.getNRandoms(cant * 12);
            double suma;
            if (r.Count > 0)
            {
                menor = r[0];
                mayor = 0;
            }
            for(int i=0;i<r.Count;i++)
            {
                suma=0;
                for (int j = 0; j < 12 && i<r.Count;j++)
                {
                    suma += r[i];
                    i++;
                }
                lstRandoms.Add((double)(suma-6)*desviacion+promedio);
                if (lstRandoms[lstRandoms.Count-1] > mayor)
                    mayor = lstRandoms[lstRandoms.Count - 1];
                if (lstRandoms[lstRandoms.Count - 1] < menor)
                    menor = lstRandoms[lstRandoms.Count - 1];
            }
            return lstRandoms;
        }
        public decimal getMayor()
        {
            return (decimal) mayor;
        }
        public decimal getMenor()
        {
            return (decimal) menor;
        }
        public decimal getIntervalo(int intervalos)
        {
            return (decimal)(mayor-menor) / intervalos;
        }
        public double getLimiteSuperior()
        {
            return mayor;
        }
        public double getLimiteInferior()
        {
            return menor;
        }
    }
}
